<?php

class Operation {
	private $message = "";
    function Operation() {
    }
    
    public function run() {
		$_SESSION['op']['is_first_enter'] = isset ($_SESSION['op']['is_first_enter']) ? 1 : 0;
		if ($_SESSION['op']['is_first_enter'] == 0) {
			$this->message = "将对词条: ".$_SESSION['NOW_MESS_ID']."进行系列操作\n".
			"1.删除该词条\t-d\n".
			"2.恢复该词条\t-r\n".
			"3.封禁调教人\t-f\n".
			"4.封禁所在群\t-c\n".
			"5.提升优先级\t-p\n".
			"6.设置开始日期\t-s\n".
			"7.设置开始时间\t-t\n".
			"8.设置失效日期\t-e\n".
			"9.设置失效时间\t-g\n".
			"退出请输入 -q";
			return;
		} 
		
		if (preg_match('/^-(\S+)\s*(.*)$/is', trim($_POST[Message]), $m)) {
			$funName = "__" . $m[1];
			
				if(method_exists($this,$funName))
				{
					$this-> $funName($m);
				}else{
					$this->message = "咦、说什么呢╮(╯▽╰)╭";
				}
				
			
		} else {
					$this->message = "貌似，命令什么的格式不对啊- -";
		}
    }
    
    private function __d() {
    	$sql = "update td_study set flag = 0 where id=".$_SESSION['NOW_MESS_ID'];
    	@DB :: Query($sql);
    	$this->message = "删除词条【{$_SESSION['NOW_MESS_ID']}】成功~" ;
    }
    
    private function __r() {
    	$sql = "update td_study set flag = 1 where id=".$_SESSION['NOW_MESS_ID'];
    	@DB :: Query($sql);
    	$this->message = "恢复词条【{$_SESSION['NOW_MESS_ID']}】成功~" ;
    }
       
       
    private function __p() {
    	$sql = "update td_study set priority = 10 where id=".$_SESSION['NOW_MESS_ID'];
    	@DB :: Query($sql);
    	$this->message = "词条【{$_SESSION['NOW_MESS_ID']}】优先级被提升为10" ;
    } 
    private function __f() {
    	$r = DB :: GetTableRow("td_study", array (
				"id" => $_SESSION['NOW_MESS_ID'] 
			));
		
		$ret = @ DB :: GetQueryResult("select * from td_blacklist where qq='{$r[qq]}' and flag=1 and clusternum='0'", true);
						$start_time = date("YmdHis", (time() + 8 * 3600));
						$end_time = date("Ymd", (time() + (24*999 + 8) * 3600)) . "235959";
						if ($ret) {
							@ DB :: Query("update  td_blacklist set start_time ='{$start_time}', end_time='{$end_time}',day=3,keword='{$v}' where flag=1 and qq='{$r[qq]}' and clusternum='0'");

						} else {
							$arr = array (
								'qq' => $r[qq],
								'clusternum' => '0',
								'start_time' => $start_time,
								'end_time' => $end_time,
								'day' => 999,
								'keword' => "管理员封禁"
							);
							DB :: SaveTableRow('td_blacklist', $arr);
						}
		$this->message = "用户[{$r[qq]}]已经被永久封禁~";
    }
    
    private function __c() {
    	$r = DB :: GetTableRow("td_study", array (
				"id" => $_SESSION['NOW_MESS_ID'] 
			));
			
		@ DB :: Query("update td_cluster_favorable set is_service=0 where clusternum='{$r[clusternum]}'");
		$this->message = "群[{$r[clusternum]}]已经被封禁~" ;
    }
    
    	private function __q($m) {
		if($_POST[Event]=="ReceiveNormalIM")
			unset ($_SESSION['NOWMODE']);
		else
			unset ($_SESSION['QUN_MODE']);
		unset ($_SESSION['op']);
		$this->message = "退出操作模式了哦，多多和我说话吧，喵~！";
	}
	
	
	private function __get($property_name) {
		return $this-> $property_name;
	}

	private function __set($property_name, $value) {
		$this->$property_name = $value;
	}
    	
}
?>